<template>
  <view class="mui-uni-tabbar-bottom">
    <view class="uni-tabbar" style="background-color: rgba(250, 250, 250, 0.8); backdrop-filter: blur(10px);">
      <view class="uni-tabbar-border" style="background-color: rgba(255, 255, 255, 0.33);" />
      <block v-for="(item, ind) in tabList" :key="item.text" class="uni-tabbar__item_wrap">
        <view v-if="hasMid === ind + 1" class="uni-tabbar__item" style="flex: 0 0 50px; position: relative;"
              @click="tabItemClick(item.pagePath)"
        >
          <view class="uni-tabbar__mid">
            <image src="/static/img/tabbar/work2.png" style="width: 36px; height: 36px;" />
          </view>
          <view class="uni-tabbar__bd" style="height: 50px;">
            <view class="uni-tabbar__icon uni-tabbar__icon__diff" style="width: 20px; height: 20px;">
              <!---->
            </view>
            <view class="uni-tabbar__label"
                  style="color: rgb(153, 153, 153); font-size: 10px; line-height: normal; margin-top: 3px;"
            >
              {{ item.text }}
            </view><!---->
          </view>
        </view>
        <view v-else class="uni-tabbar__item" @click="tabChange(item.pagePath, ind)">
          <view class="uni-tabbar__bd" style="height: 50px;">
            <view class="uni-tabbar__icon uni-tabbar__icon__diff" style="width: 20px; height: 20px;">
              <!-- <image :src="current === ind ? item.selectedIconPath : item.iconPath" /> -->
              <uni-icons custom-prefix="iconfont" size="22" :color="current === ind ? '#02b28b' : 'rgb(153, 153, 153)'"
                         :type="current === ind ? item.selectedIconPath : item.iconPath"
              />
            </view>
            <view class="uni-tabbar__label" :style="{ color: current === ind ? '#02b28b' : 'rgb(153, 153, 153)' }"
                  style="font-size: 10px; line-height: normal; margin-top: 3px;"
            >
              {{ item.text }}
            </view><!---->
            <view v-if="getBadgeIndex === ind" class="uni-tabbar__reddot uni-tabbar__badge">
              {{ badgeText }}
            </view>
          </view>
        </view>
      </block>
    </view>
    <view class="uni-placeholder" style="height: 50px;" />
  </view>
</template>

<script>
export default {
  // 翻转
  name: 'MuiBottomTabbar',
  props: {
    modelValue: {
      type: Number,
      default: 0
    },
    // 固定底部
    fixedBottom: {
      type: Boolean,
      default: true
    },
    tabList: {
      type: Array,
      default: () => {
        return []
      }
    },
    badgeIndex: {
      type: Number,
      default: -1
    },
    badgeText: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      showMsgInd: -1
    }
  },
  computed: {
    getBadgeIndex() {
      if (this.badgeText === '0') return -1
      return this.badgeIndex
    },
    hasMid() {
      return false // this.tabList.length % 2 === 0 ? -1 : Math.ceil(this.tabList.length / 2)
    },
    current: {
      get() {
        return this.modelValue
      },
      set(newVal) {
        this.$emit('update:modelValue', newVal)
      }
    }
  },
  methods: {
    tabChange(_pagePath, index) {
      this.current = index
    },
    tabItemClick(path) {
      uni.$util.push(path)
    }
  }
}
</script>

<style scoped lang="scss">
.mui-uni-tabbar-bottom {
  position: fixed;
  left: var(--window-left);
  right: var(--window-right);
  bottom: 0;
  box-sizing: border-box;
  width: 100%;
  z-index: 998;

  .uni-tabbar-bottom .uni-tabbar {
  }

  .uni-tabbar-bottom {
    /*    display: block;
      box-sizing: border-box;
      width: 100%; */
  }

  .uni-tabbar {
    position: fixed;
    left: var(--window-left);
    right: var(--window-right);
    z-index: 998;
    display: flex;
    bottom: 0;
    padding-bottom: 0;
    padding-bottom: constant(safe-area-inset-bottom);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .uni-tabbar-border {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 1px;
    transform: scaleY(0.5);
  }

  .uni-tabbar__item_wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    flex: 1;
  }

  .uni-tabbar__item {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    flex: 1;
    font-size: 0;
    text-align: center;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  }

  .uni-tabbar__bd {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }

  .uni-tabbar__mid {
    display: flex;
    justify-content: center;
    position: absolute;
    bottom: 8px;
    background-size: 100% 100%;
    width: 50px;
    height: 50px;
  }

  .uni-tabbar__icon.uni-tabbar__icon__diff {
    margin-top: 0px;
    width: 34px;
    height: 34px;
  }

  .uni-tabbar__icon {
    position: relative;
    display: inline-block;
    margin-top: 5px;
  }

  .uni-tabbar__icon image {
    width: 100%;
    height: 100%;
  }

  .uni-tabbar__label {
    position: relative;
    text-align: center;
    font-size: 10px;
  }

  .uni-tabbar-bottom .uni-placeholder {
    height: 100rpx;
    width: 100%;
    margin-bottom: 0;
    margin-bottom: constant(safe-area-inset-bottom);
    margin-bottom: env(safe-area-inset-bottom);
  }

  .uni-tabbar__reddot {
    position: absolute;
    top: 2px;
    right: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: #f43530;
    color: #ffffff;
    transform: translate(40%, 0%);
  }

  .uni-tabbar__badge {
    width: auto;
    height: 16px;
    line-height: 16px;
    border-radius: 16px;
    min-width: 16px;
    padding: 0 2px;
    font-size: 12px;
    text-align: center;
    white-space: nowrap;
  }
}
</style>
